import 'dart:io';

import 'package:bruno/bruno.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:getwidget/getwidget.dart';
import 'package:meal/constant/antd_icons.dart';
import 'package:meal/constant/sizes.dart';
import 'package:meal/model/product.dart';
import 'package:meal/route/route.dart';
import 'package:meal/utils/colors.dart';
import 'package:meal/utils/styles.dart';
import 'package:meal/utils/tools.dart';

///
/// 编辑商品套餐
///
class EditSetMeal extends StatefulWidget {
  final ProductModel product;

  const EditSetMeal({Key? key, required this.product}) : super(key: key);

  @override
  State<EditSetMeal> createState() => _EditSetMealState();
}

class _EditSetMealState extends State<EditSetMeal> {
  List<BrnMultiDataPickerEntity> types = [];

  List<String> imgs = [
    'https://img1.baidu.com/it/u=858635807,3718531454&fm=253&fmt=auto&app=138&f=PNG?w=500&h=333',
    'https://img1.baidu.com/it/u=469912558,501769667&fm=253&fmt=auto&app=138&f=JPEG?w=752&h=500',
  ];

  List<String> tags = ['加香菜', '加葱花', '加生菜', '加辣椒'];

  bool delivery = false;

  bool timeLimit = true;

  bool limited = true;

  bool news = true;

  bool specialtyDish = true;

  bool promotion = true;

  double get leftWidth {
    return Sizes.default80;
  }

  double get rowHeight {
    return Sizes.default50;
  }

  TextSpan get requiredSpan {
    return TextSpan(text: ' *', style: StylesUtils.customTextStyle(color: ColorsUtils.colorFf0));
  }

  TextStyle get defaultStyle {
    return StylesUtils.customTextStyle(color: ColorsUtils.color333);
  }

  @override
  void initState() {
    super.initState();
    types.add(BrnMultiDataPickerEntity(text: '小馄饨类', value: 1));
    types.add(BrnMultiDataPickerEntity(text: '中馄饨类', value: 2));
    types.add(BrnMultiDataPickerEntity(text: '大馄饨类', value: 3));
    types.add(BrnMultiDataPickerEntity(text: '汤粉面类', value: 4));
    types.add(BrnMultiDataPickerEntity(text: '炒粉/面/饭', value: 5));
    types.add(BrnMultiDataPickerEntity(text: '大馄饨类', value: 6));
    types.add(BrnMultiDataPickerEntity(text: '配菜小吃', value: 7));
    types.add(BrnMultiDataPickerEntity(text: '糖水类', value: 8));
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        Container(
          height: Sizes.default50,
          alignment: Alignment.centerLeft,
          padding: const EdgeInsets.symmetric(horizontal: Sizes.default15),
          child: Text('基本信息',
              style: StylesUtils.customTextStyle(
                  color: ColorsUtils.color797, fontSize: Sizes.default13)),
        ),
        Container(
          padding:
              const EdgeInsets.symmetric(vertical: Sizes.default10, horizontal: Sizes.default15),
          decoration: const BoxDecoration(color: Colors.white),
          child: ListBody(
            children: [
              Row(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Container(
                    alignment: Alignment.topLeft,
                    width: leftWidth,
                    child: Text.rich(
                        TextSpan(text: '商品图片', style: defaultStyle, children: [requiredSpan])),
                  ),
                  Expanded(
                      child: Container(
                    alignment: Alignment.topLeft,
                    child: Wrap(
                        spacing: Sizes.default10,
                        runSpacing: Sizes.default10,
                        children: imgs
                            .asMap()
                            .map((i, url) {
                              return MapEntry(i, image(url, i));
                            })
                            .values
                            .toList()),
                  ))
                ],
              ),
              Container(
                height: rowHeight,
                alignment: Alignment.centerLeft,
                child: Row(
                  children: [
                    Container(
                        width: leftWidth,
                        alignment: Alignment.centerLeft,
                        child: Text.rich(
                          TextSpan(text: '名称', style: defaultStyle, children: [requiredSpan]),
                        )),
                    Expanded(
                        child: Container(
                      height: Sizes.default45,
                      padding: const EdgeInsets.symmetric(horizontal: Sizes.default10),
                      decoration: BoxDecoration(
                          color: ColorsUtils.rgba(247, 247, 247, 1),
                          borderRadius: const BorderRadius.all(Radius.circular(Sizes.default10))),
                      child: TextField(
                        controller: ToolsUtils.editingController(widget.product.name),
                        style: StylesUtils.customTextStyle(
                            color: ColorsUtils.color363, fontSize: Sizes.default15),
                        decoration: InputDecoration(
                            border: const OutlineInputBorder(
                              borderSide: BorderSide.none,
                            ),
                            isCollapsed: true,
                            filled: true,
                            fillColor: Colors.transparent,
                            contentPadding: const EdgeInsets.symmetric(
                                horizontal: Sizes.default10, vertical: Sizes.default10),
                            constraints: const BoxConstraints(minHeight: Sizes.default45),
                            hintText: '如柠檬茶',
                            hintStyle: StylesUtils.customTextStyle(
                                fontSize: Sizes.default14, color: ColorsUtils.color999)),
                        keyboardType: TextInputType.text,
                        onChanged: (String content) {},
                      ),
                    ))
                  ],
                ),
              ),
              Container(
                height: rowHeight,
                alignment: Alignment.centerLeft,
                child: Row(
                  children: [
                    Container(
                        width: leftWidth,
                        alignment: Alignment.centerLeft,
                        child: Text.rich(
                          TextSpan(text: '商品分类', style: defaultStyle, children: [requiredSpan]),
                        )),
                    Expanded(
                      child: InkWell(
                        child: Container(
                          height: Sizes.default45,
                          padding: const EdgeInsets.symmetric(horizontal: Sizes.default10),
                          alignment: Alignment.centerLeft,
                          decoration: BoxDecoration(
                              color: ColorsUtils.rgba(247, 247, 247, 1),
                              borderRadius:
                                  const BorderRadius.all(Radius.circular(Sizes.default10))),
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Text('请选择分类',
                                  style: StylesUtils.customTextStyle(
                                      fontSize: Sizes.default15, color: ColorsUtils.color797)),
                              BrunoTools.getAssetSizeImage(BrnAsset.iconRightArrow, 16, 16)
                            ],
                          ),
                        ),
                        onTap: () {
                          ToolsUtils.openDataPicker(context, types, (selectedIndexList) {
                            // int index = selectedIndexList[0];
                            // BrnMultiDataPickerEntity entity = types[index];
                            setState(() {});
                          });
                        },
                      ),
                    ),
                  ],
                ),
              ),
              Container(
                height: rowHeight,
                alignment: Alignment.centerLeft,
                child: Row(
                  children: [
                    Container(
                      width: leftWidth,
                      alignment: Alignment.centerLeft,
                      child: Text(
                        '商品编号',
                        style: defaultStyle,
                      ),
                    ),
                    Expanded(
                        child: Container(
                      height: Sizes.default45,
                      padding: const EdgeInsets.symmetric(horizontal: Sizes.default10),
                      decoration: BoxDecoration(
                          color: ColorsUtils.rgba(247, 247, 247, 1),
                          borderRadius: const BorderRadius.all(Radius.circular(Sizes.default10))),
                      child: TextField(
                        controller: ToolsUtils.editingController('A01'),
                        style: StylesUtils.customTextStyle(
                            color: ColorsUtils.color363, fontSize: Sizes.default15),
                        decoration: InputDecoration(
                            border: const OutlineInputBorder(
                              borderSide: BorderSide.none,
                            ),
                            isCollapsed: true,
                            filled: true,
                            fillColor: Colors.transparent,
                            contentPadding: const EdgeInsets.symmetric(
                                horizontal: Sizes.default10, vertical: Sizes.default10),
                            constraints: const BoxConstraints(minHeight: Sizes.default45),
                            hintText: '例如A0179281',
                            hintStyle: StylesUtils.customTextStyle(
                                fontSize: Sizes.default14, color: ColorsUtils.color999)),
                        keyboardType: TextInputType.text,
                        onChanged: (String content) {},
                      ),
                    ))
                  ],
                ),
              ),
              Container(
                height: rowHeight,
                alignment: Alignment.centerLeft,
                child: Row(
                  children: [
                    Container(
                        width: leftWidth,
                        alignment: Alignment.centerLeft,
                        child: Text(
                          '过期日期',
                          style: defaultStyle,
                        )),
                    Expanded(
                      child: InkWell(
                        child: Container(
                          height: Sizes.default45,
                          padding: const EdgeInsets.symmetric(horizontal: Sizes.default10),
                          alignment: Alignment.centerLeft,
                          decoration: BoxDecoration(
                              color: ColorsUtils.rgba(247, 247, 247, 1),
                              borderRadius:
                                  const BorderRadius.all(Radius.circular(Sizes.default10))),
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Text('商超类商品过期日期',
                                  style: StylesUtils.customTextStyle(
                                      fontSize: Sizes.default15, color: ColorsUtils.color797)),
                              BrunoTools.getAssetSizeImage(BrnAsset.iconRightArrow, 16, 16)
                            ],
                          ),
                        ),
                        onTap: () {
                          ToolsUtils.openDatePicker(context,
                              onConfirm: (DateTime dateTime, List<int> selectedIndex) {
                            BrnToast.show("onConfirm:  $dateTime   $selectedIndex", context);
                          });
                        },
                      ),
                    ),
                  ],
                ),
              ),
              Container(
                height: rowHeight,
                alignment: Alignment.centerLeft,
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text('单点不配送', style: defaultStyle),
                    GFToggle(
                      onChanged: (bool? val) {
                        setState(() {
                          delivery = val!;
                        });
                      },
                      value: delivery,
                      type: GFToggleType.ios,
                      boxShape: BoxShape.circle,
                      enabledTrackColor: ColorsUtils.rgba(255, 110, 83, 1),
                      enabledThumbColor: Colors.white,
                    )
                  ],
                ),
              ),
            ],
          ),
        ),
        Container(
          height: Sizes.default50,
          alignment: Alignment.centerLeft,
          padding: const EdgeInsets.symmetric(horizontal: Sizes.default15),
          child: Text('商品描述',
              style: StylesUtils.customTextStyle(
                  color: ColorsUtils.color797, fontSize: Sizes.default13)),
        ),
        Container(
          padding:
              const EdgeInsets.symmetric(vertical: Sizes.default10, horizontal: Sizes.default15),
          decoration: const BoxDecoration(color: Colors.white),
          child: ListBody(
            children: [
              Container(
                height: rowHeight,
                alignment: Alignment.centerLeft,
                child: Row(
                  children: [
                    Container(
                      width: leftWidth,
                      alignment: Alignment.centerLeft,
                      child: Text(
                        '商品类型',
                        style: defaultStyle,
                      ),
                    ),
                    Container(
                      alignment: Alignment.center,
                      constraints: const BoxConstraints.expand(width: 75, height: Sizes.default30),
                      decoration: BoxDecoration(
                          color: ColorsUtils.rgba(255, 238, 238, 1),
                          borderRadius: BorderRadius.circular(Sizes.default15),
                          border: Border.all(color: ColorsUtils.rgba(255, 110, 83, 1))),
                      child: Text(
                        '套餐',
                        style: StylesUtils.customTextStyle(color: ColorsUtils.colorFf6),
                      ),
                    )
                  ],
                ),
              ),
              Row(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Container(
                    width: leftWidth,
                    alignment: Alignment.centerLeft,
                    child: Text(
                      '描述',
                      style: StylesUtils.customTextStyle(color: ColorsUtils.color333),
                    ),
                  ),
                  Expanded(
                      child: BrnInputText(
                    borderRadius: Sizes.default10,
                    borderColor: ColorsUtils.rgba(247, 247, 247, 1),
                    bgColor: ColorsUtils.rgba(247, 247, 247, 1),
                    minLines: 2,
                    maxLength: 200,
                    minHeight: 105,
                    padding: const EdgeInsets.all(Sizes.default10),
                    hint: '请输入描述',
                    autoFocus: false,
                    textString: '广西北海市海城区码头镇流下村特色早餐小吃',
                  ))
                ],
              ),
              Container(
                padding: const EdgeInsets.symmetric(vertical: Sizes.default10),
                child: Row(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Container(
                      width: leftWidth,
                      alignment: Alignment.centerLeft,
                      child: Text(
                        '套餐内容',
                        style: StylesUtils.customTextStyle(color: ColorsUtils.color333),
                      ),
                    ),
                    Expanded(
                        child: BrnInputText(
                          borderRadius: Sizes.default10,
                          borderColor: ColorsUtils.rgba(247, 247, 247, 1),
                          bgColor: ColorsUtils.rgba(247, 247, 247, 1),
                          minLines: 2,
                          maxLength: 200,
                          minHeight: 105,
                          padding: const EdgeInsets.all(Sizes.default10),
                          hint: '请输入描述',
                          autoFocus: false,
                          textString: '双蛋肠粉+豆浆',
                        ))
                  ],
                ),
              ),
              Container(
                height: rowHeight,
                alignment: Alignment.centerLeft,
                child: Row(
                  children: [
                    Container(
                        width: leftWidth,
                        alignment: Alignment.centerLeft,
                        child: Text(
                          '主料',
                          style: defaultStyle,
                        )),
                    Expanded(
                        child: Container(
                      height: Sizes.default45,
                      padding: const EdgeInsets.symmetric(horizontal: Sizes.default10),
                      decoration: BoxDecoration(
                          color: ColorsUtils.rgba(247, 247, 247, 1),
                          borderRadius: const BorderRadius.all(Radius.circular(Sizes.default10))),
                      child: TextField(
                        style: StylesUtils.customTextStyle(
                            color: ColorsUtils.color363, fontSize: Sizes.default15),
                        decoration: InputDecoration(
                            border: const OutlineInputBorder(
                              borderSide: BorderSide.none,
                            ),
                            isCollapsed: true,
                            filled: true,
                            fillColor: Colors.transparent,
                            contentPadding: const EdgeInsets.symmetric(
                                horizontal: Sizes.default10, vertical: Sizes.default10),
                            constraints: const BoxConstraints(minHeight: Sizes.default45),
                            hintText: '如鸡肉',
                            hintStyle: StylesUtils.customTextStyle(
                                fontSize: Sizes.default14, color: ColorsUtils.color999)),
                        keyboardType: TextInputType.text,
                        onChanged: (String content) {},
                      ),
                    ))
                  ],
                ),
              ),
              Container(
                height: rowHeight,
                alignment: Alignment.centerLeft,
                child: Row(
                  children: [
                    Container(
                        width: leftWidth,
                        alignment: Alignment.centerLeft,
                        child: Text('口味', style: defaultStyle)),
                    Expanded(
                        child: Container(
                      height: Sizes.default45,
                      padding: const EdgeInsets.symmetric(horizontal: Sizes.default10),
                      decoration: BoxDecoration(
                          color: ColorsUtils.rgba(247, 247, 247, 1),
                          borderRadius: const BorderRadius.all(Radius.circular(Sizes.default10))),
                      child: TextField(
                        style: StylesUtils.customTextStyle(
                            color: ColorsUtils.color363, fontSize: Sizes.default15),
                        decoration: InputDecoration(
                            border: const OutlineInputBorder(
                              borderSide: BorderSide.none,
                            ),
                            isCollapsed: true,
                            filled: true,
                            fillColor: Colors.transparent,
                            contentPadding: const EdgeInsets.symmetric(
                                horizontal: Sizes.default10, vertical: Sizes.default10),
                            constraints: const BoxConstraints(minHeight: Sizes.default45),
                            hintText: '如微辣',
                            hintStyle: StylesUtils.customTextStyle(
                                fontSize: Sizes.default14, color: ColorsUtils.color999)),
                        keyboardType: TextInputType.text,
                        onChanged: (String content) {},
                      ),
                    ))
                  ],
                ),
              ),
              Container(
                height: rowHeight,
                alignment: Alignment.centerLeft,
                child: Row(
                  children: [
                    Container(
                      width: leftWidth,
                      alignment: Alignment.centerLeft,
                      child: Text(
                        '制作时长',
                        style: defaultStyle,
                      ),
                    ),
                    Expanded(
                        child: Container(
                      height: Sizes.default45,
                      padding: const EdgeInsets.symmetric(horizontal: Sizes.default10),
                      margin: const EdgeInsets.only(right: Sizes.default15),
                      decoration: BoxDecoration(
                          color: ColorsUtils.rgba(247, 247, 247, 1),
                          borderRadius: const BorderRadius.all(Radius.circular(Sizes.default10))),
                      child: TextField(
                        style: StylesUtils.customTextStyle(
                            color: ColorsUtils.color363, fontSize: Sizes.default15),
                        decoration: InputDecoration(
                            border: const OutlineInputBorder(
                              borderSide: BorderSide.none,
                            ),
                            isCollapsed: true,
                            filled: true,
                            fillColor: Colors.transparent,
                            contentPadding: const EdgeInsets.symmetric(
                                horizontal: Sizes.default10, vertical: Sizes.default10),
                            constraints: const BoxConstraints(minHeight: Sizes.default45),
                            hintText: '请输入时长',
                            hintStyle: StylesUtils.customTextStyle(
                                fontSize: Sizes.default14, color: ColorsUtils.color999)),
                        keyboardType: TextInputType.number,
                        onChanged: (String content) {},
                      ),
                    )),
                    Container(
                      alignment: Alignment.centerRight,
                      child: Text('min',
                          style: StylesUtils.customTextStyle(color: ColorsUtils.color333)),
                    )
                  ],
                ),
              ),
            ],
          ),
        ),
        Container(
          height: Sizes.default50,
          alignment: Alignment.centerLeft,
          padding: const EdgeInsets.symmetric(horizontal: Sizes.default15),
          child: Text('规格属性',
              style: StylesUtils.customTextStyle(
                  color: ColorsUtils.color797, fontSize: Sizes.default13)),
        ),
        Container(
          padding:
              const EdgeInsets.symmetric(vertical: Sizes.default10, horizontal: Sizes.default15),
          decoration: const BoxDecoration(color: Colors.white),
          child: ListBody(
            children: [
              Container(
                height: rowHeight,
                alignment: Alignment.centerLeft,
                child: Row(
                  children: [
                    Container(
                        width: leftWidth,
                        alignment: Alignment.centerLeft,
                        child: Text(
                          '套餐规格',
                          style: defaultStyle,
                        )),
                    Expanded(
                      child: InkWell(
                        child: Container(
                          height: Sizes.default45,
                          padding: const EdgeInsets.symmetric(horizontal: Sizes.default10),
                          alignment: Alignment.centerLeft,
                          decoration: BoxDecoration(
                              color: ColorsUtils.rgba(247, 247, 247, 1),
                              borderRadius:
                                  const BorderRadius.all(Radius.circular(Sizes.default10))),
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Text('添加规格2/5',
                                  style: StylesUtils.customTextStyle(
                                      fontSize: Sizes.default15, color: ColorsUtils.color797)),
                              BrunoTools.getAssetSizeImage(BrnAsset.iconRightArrow, 16, 16)
                            ],
                          ),
                        ),
                        onTap: () {
                          Get.toNamed(RouteGet.productMeal);
                        },
                      ),
                    ),
                  ],
                ),
              ),
              Container(
                decoration: BoxDecoration(
                    border: Border.all(color: ColorsUtils.rgba(228, 228, 228, 1)),
                    color: ColorsUtils.rgba(255, 255, 255, 1),
                    borderRadius: BorderRadius.circular(Sizes.default5)),
                padding: const EdgeInsets.all(Sizes.default10),
                margin: const EdgeInsets.only(bottom: Sizes.default20),
                child: ListBody(
                  children: [
                    Container(
                      alignment: Alignment.centerLeft,
                      margin: const EdgeInsets.only(bottom: Sizes.default15),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text('【套餐规格】', style: defaultStyle),
                          IconButton(
                              onPressed: () {},
                              icon: Icon(
                                AntdIcons.deleteFill,
                                color: ColorsUtils.parseColorFromHexString(ColorsUtils.colorFf6),
                                size: Sizes.default20,
                              ))
                        ],
                      ),
                    ),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Text('规格名称',
                            style: StylesUtils.customTextStyle(color: ColorsUtils.color333)),
                        Text('规格A',
                            style: StylesUtils.customTextStyle(color: ColorsUtils.color797)),
                      ],
                    ),
                    Container(
                      margin: const EdgeInsets.only(top: Sizes.default15),
                      height: Sizes.default30,
                      alignment: Alignment.center,
                      decoration: BoxDecoration(
                          color: ColorsUtils.rgba(242, 242, 242, 1),
                          borderRadius: BorderRadius.circular(Sizes.default5)),
                      child: Text('双蛋肠粉/99份',
                          style: StylesUtils.customTextStyle(color: ColorsUtils.color797)),
                    ),
                    Container(
                        margin: const EdgeInsets.only(top: Sizes.default15),
                        height: Sizes.default30,
                        alignment: Alignment.center,
                        decoration: BoxDecoration(
                            color: ColorsUtils.rgba(242, 242, 242, 1),
                            borderRadius: BorderRadius.circular(Sizes.default5)),
                        child: Text(
                          '肉蛋肠粉/94份',
                          style: StylesUtils.customTextStyle(
                              color: ColorsUtils.color797, fontSize: Sizes.default13),
                        )),
                    Container(
                        margin: const EdgeInsets.only(top: Sizes.default15),
                        height: Sizes.default30,
                        alignment: Alignment.center,
                        decoration: BoxDecoration(
                            color: ColorsUtils.rgba(242, 242, 242, 1),
                            borderRadius: BorderRadius.circular(Sizes.default5)),
                        child: Text(
                          '鸡蛋油条肠粉/45份',
                          style: StylesUtils.customTextStyle(
                              color: ColorsUtils.color797, fontSize: Sizes.default13),
                        )),
                  ],
                ),
              ),
              Container(
                decoration: BoxDecoration(
                    border: Border.all(color: ColorsUtils.rgba(228, 228, 228, 1)),
                    color: ColorsUtils.rgba(255, 255, 255, 1),
                    borderRadius: BorderRadius.circular(Sizes.default5)),
                padding: const EdgeInsets.all(Sizes.default10),
                margin: const EdgeInsets.only(bottom: Sizes.default20),
                child: ListBody(
                  children: [
                    Container(
                      alignment: Alignment.centerLeft,
                      margin: const EdgeInsets.only(bottom: Sizes.default15),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text('【套餐规格】', style: defaultStyle),
                          IconButton(
                              onPressed: () {},
                              icon: Icon(
                                AntdIcons.deleteFill,
                                color: ColorsUtils.parseColorFromHexString(ColorsUtils.colorFf6),
                                size: Sizes.default20,
                              ))
                        ],
                      ),
                    ),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Text('规格名称',
                            style: StylesUtils.customTextStyle(color: ColorsUtils.color333)),
                        Text('规格B',
                            style: StylesUtils.customTextStyle(color: ColorsUtils.color797)),
                      ],
                    ),
                    Container(
                        margin: const EdgeInsets.only(top: Sizes.default15),
                        height: Sizes.default30,
                        alignment: Alignment.center,
                        decoration: BoxDecoration(
                            color: ColorsUtils.rgba(242, 242, 242, 1),
                            borderRadius: BorderRadius.circular(Sizes.default5)),
                        child: Text(
                          '绿豆沙/10份',
                          style: StylesUtils.customTextStyle(
                              color: ColorsUtils.color797, fontSize: Sizes.default13),
                        )),
                    Container(
                        margin: const EdgeInsets.only(top: Sizes.default15),
                        height: Sizes.default30,
                        alignment: Alignment.center,
                        decoration: BoxDecoration(
                            color: ColorsUtils.rgba(242, 242, 242, 1),
                            borderRadius: BorderRadius.circular(Sizes.default5)),
                        child: Text(
                          '豆浆/10份',
                          style: StylesUtils.customTextStyle(
                              color: ColorsUtils.color797, fontSize: Sizes.default13),
                        )),
                  ],
                ),
              ),
              Container(
                decoration: BoxDecoration(
                    border: Border.all(color: ColorsUtils.rgba(228, 228, 228, 1)),
                    color: ColorsUtils.rgba(255, 255, 255, 1),
                    borderRadius: BorderRadius.circular(Sizes.default5)),
                padding: const EdgeInsets.all(Sizes.default10),
                margin: const EdgeInsets.only(bottom: Sizes.default20),
                child: ListBody(
                  children: [
                    Container(
                        alignment: Alignment.centerLeft,
                        margin: const EdgeInsets.only(bottom: Sizes.default15),
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Text(
                              '【商品属性】',
                              style: defaultStyle,
                            ),
                            IconButton(
                                onPressed: () {},
                                icon: Icon(
                                  AntdIcons.deleteFill,
                                  color: ColorsUtils.parseColorFromHexString(ColorsUtils.colorFf6),
                                  size: Sizes.default20,
                                ))
                          ],
                        )),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Text('属性', style: StylesUtils.customTextStyle(color: ColorsUtils.color333)),
                        Text('辅料', style: StylesUtils.customTextStyle(color: ColorsUtils.color333)),
                      ],
                    ),
                    Container(
                        margin: const EdgeInsets.only(top: Sizes.default15),
                        alignment: Alignment.centerLeft,
                        child: GridView(
                            physics: const NeverScrollableScrollPhysics(),
                            padding: const EdgeInsets.symmetric(
                                horizontal: Sizes.default15, vertical: Sizes.default10),
                            gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
                                crossAxisCount: 2,
                                mainAxisSpacing: Sizes.default10,
                                crossAxisSpacing: Sizes.default10,
                                childAspectRatio: 4.0 //宽高比为4
                                ),
                            shrinkWrap: true,
                            children: tags
                                .map((e) => Container(
                                    width: 120,
                                    height: 30,
                                    decoration: BoxDecoration(
                                        color: ColorsUtils.rgba(242, 242, 242, 1),
                                        borderRadius: BorderRadius.circular(Sizes.default5)),
                                    alignment: Alignment.center,
                                    child: Text(
                                      e,
                                      style: StylesUtils.customTextStyle(
                                          fontSize: Sizes.default13, color: ColorsUtils.color333),
                                    )))
                                .toList())),
                  ],
                ),
              ),
              Container(
                height: rowHeight,
                alignment: Alignment.centerLeft,
                child: Row(
                  children: [
                    Container(
                      width: leftWidth,
                      alignment: Alignment.centerLeft,
                      child: Text(
                        '价格',
                        style: defaultStyle,
                      ),
                    ),
                    Expanded(
                        child: Container(
                      height: Sizes.default45,
                      padding: const EdgeInsets.symmetric(horizontal: Sizes.default10),
                      margin: const EdgeInsets.only(right: Sizes.default15),
                      decoration: BoxDecoration(
                          color: ColorsUtils.rgba(247, 247, 247, 1),
                          borderRadius: const BorderRadius.all(Radius.circular(Sizes.default10))),
                      child: TextField(
                        controller: ToolsUtils.editingController('150'),
                        style: StylesUtils.customTextStyle(
                            color: ColorsUtils.color363, fontSize: Sizes.default15),
                        decoration: InputDecoration(
                            border: const OutlineInputBorder(
                              borderSide: BorderSide.none,
                            ),
                            isCollapsed: true,
                            filled: true,
                            fillColor: Colors.transparent,
                            contentPadding: const EdgeInsets.symmetric(
                                horizontal: Sizes.default10, vertical: Sizes.default10),
                            constraints: const BoxConstraints(minHeight: Sizes.default45),
                            hintText: '请输入价格',
                            hintStyle: StylesUtils.customTextStyle(
                                fontSize: Sizes.default14, color: ColorsUtils.color999)),
                        keyboardType: TextInputType.number,
                        onChanged: (String content) {},
                      ),
                    )),
                    Container(
                      alignment: Alignment.centerRight,
                      child: Text('￥',
                          style: StylesUtils.customTextStyle(color: ColorsUtils.color333)),
                    )
                  ],
                ),
              ),
              Container(
                height: rowHeight,
                alignment: Alignment.centerLeft,
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text('打包费',
                        style: StylesUtils.customTextStyle(
                            fontSize: Sizes.default15, color: ColorsUtils.color333)),
                    Text(
                      '2 ￥/份',
                      style: StylesUtils.customTextStyle(
                          fontSize: Sizes.default15, color: ColorsUtils.color797),
                    ),
                  ],
                ),
              ),
            ],
          ),
        ),
        Container(
          height: Sizes.default50,
          alignment: Alignment.centerLeft,
          padding: const EdgeInsets.symmetric(horizontal: Sizes.default15),
          child: Text('限时限量',
              style: StylesUtils.customTextStyle(
                  color: ColorsUtils.color797, fontSize: Sizes.default13)),
        ),
        Container(
          padding:
              const EdgeInsets.symmetric(vertical: Sizes.default10, horizontal: Sizes.default15),
          decoration: const BoxDecoration(color: Colors.white),
          child: ListBody(
            children: [
              Container(
                height: rowHeight,
                alignment: Alignment.centerLeft,
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text(
                      '是否限时开售',
                      style: defaultStyle,
                    ),
                    GFToggle(
                      onChanged: (bool? val) {
                        setState(() {
                          timeLimit = val!;
                        });
                      },
                      value: timeLimit,
                      type: GFToggleType.ios,
                      boxShape: BoxShape.circle,
                      enabledTrackColor: ColorsUtils.rgba(255, 110, 83, 1),
                      enabledThumbColor: Colors.white,
                    )
                  ],
                ),
              ),
              Container(
                height: rowHeight,
                alignment: Alignment.centerLeft,
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text(
                      '是否限量供应',
                      style: StylesUtils.customTextStyle(
                          fontSize: Sizes.default15, color: ColorsUtils.color333),
                    ),
                    GFToggle(
                      onChanged: (bool? val) {
                        setState(() {
                          limited = val!;
                        });
                      },
                      value: limited,
                      type: GFToggleType.ios,
                      boxShape: BoxShape.circle,
                      enabledTrackColor: ColorsUtils.rgba(255, 110, 83, 1),
                      enabledThumbColor: Colors.white,
                    )
                  ],
                ),
              ),
            ],
          ),
        ),
        Container(
          height: Sizes.default50,
          alignment: Alignment.centerLeft,
          padding: const EdgeInsets.symmetric(horizontal: Sizes.default15),
          child: Text('新品促销',
              style: StylesUtils.customTextStyle(
                  color: ColorsUtils.color797, fontSize: Sizes.default13)),
        ),
        Container(
          padding:
          const EdgeInsets.symmetric(vertical: Sizes.default10, horizontal: Sizes.default15),
          decoration: const BoxDecoration(color: Colors.white),
          child: ListBody(
            children: [
              Container(
                height: rowHeight,
                alignment: Alignment.centerLeft,
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text(
                      '是否新品',
                      style: StylesUtils.customTextStyle(
                          fontSize: Sizes.default15, color: ColorsUtils.color333),
                    ),
                    GFToggle(
                      onChanged: (bool? val) {
                        setState(() {
                          news = val!;
                        });
                      },
                      value: news,
                      type: GFToggleType.ios,
                      boxShape: BoxShape.circle,
                      enabledTrackColor: ColorsUtils.rgba(255, 110, 83, 1),
                      enabledThumbColor: Colors.white,
                    )
                  ],
                ),
              ),
              Container(
                height: rowHeight,
                alignment: Alignment.centerLeft,
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text(
                      '是否招牌菜',
                      style: StylesUtils.customTextStyle(
                          fontSize: Sizes.default15, color: ColorsUtils.color333),
                    ),
                    GFToggle(
                      onChanged: (bool? val) {
                        setState(() {
                          specialtyDish = val!;
                        });
                      },
                      value: specialtyDish,
                      type: GFToggleType.ios,
                      boxShape: BoxShape.circle,
                      enabledTrackColor: ColorsUtils.rgba(255, 110, 83, 1),
                      enabledThumbColor: Colors.white,
                    )
                  ],
                ),
              ),
              Container(
                height: rowHeight,
                alignment: Alignment.centerLeft,
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text(
                      '是否促销',
                      style: StylesUtils.customTextStyle(
                          fontSize: Sizes.default15, color: ColorsUtils.color333),
                    ),
                    GFToggle(
                      onChanged: (bool? val) {
                        setState(() {
                          promotion = val!;
                        });
                      },
                      value: promotion,
                      type: GFToggleType.ios,
                      boxShape: BoxShape.circle,
                      enabledTrackColor: ColorsUtils.rgba(255, 110, 83, 1),
                      enabledThumbColor: Colors.white,
                    )
                  ],
                ),
              ),
            ],
          ),
        ),
      ],
    );
  }

  Widget image(String url, int index) {
    return GFImageOverlay(
      width: 105,
      height: 105,
      alignment: Alignment.center,
      borderRadius: BorderRadius.circular(Sizes.default10),
      image: bgImg(url),
      child: imgs.length == index + 1
          ? ToolsUtils.getUrlSvg('https://cdn7.axureshop.com/demo/1525603/images/发布商品_单品/u1046.svg',
              width: 24, height: 20)
          : const Text(''),
    );
  }

  dynamic bgImg(String path) {
    if (path.startsWith(RegExp(r'^http(s)?'))) {
      return NetworkImage(path);
    }
    return FileImage(File(path));
  }
}
